package com.example.master.service.Impl;

import com.example.master.entity.Service;
import com.example.master.entity.User;
import com.example.master.entity.vo.ServiceDetailVo;
import com.example.master.mapper.CommentMapper;
import com.example.master.mapper.OrderMapper;
import com.example.master.mapper.ServiceMapper;
import com.example.master.mapper.UserMapper;
import com.example.master.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;

@org.springframework.stereotype.Service
public class ProductServiceImpl  implements ProductService {

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    ServiceMapper serviceMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public ServiceDetailVo getDetailService(Integer id){
        ServiceDetailVo productDetailVo=new ServiceDetailVo();
        Service serviceById = serviceMapper.getServiceById(id);
        productDetailVo.setId(serviceById.getId());
        productDetailVo.setPayType(serviceById.getPayType());
        productDetailVo.setPrice(serviceById.getPrice());
        productDetailVo.setRemark(serviceById.getRemark());
        productDetailVo.setServiceImg(serviceById.getServiceImg());

        //卖家id
        Integer createBy = serviceById.getCreateBy();
        User userById =userMapper.getUserById(createBy);
        //卖家的昵称和图片地址
        productDetailVo.setSellerNickName(userById.getNickName());
        productDetailVo.setSellerAvatar(userById.getAvatarUrl());

        //服务销量
        Integer integer = orderMapper.countOrderNum(id);
        productDetailVo.setSellCount(integer);

        //信誉等级
        Float creditRating = commentMapper.getCreditRating(createBy);
        productDetailVo.setSellerLevel(creditRating);
        return productDetailVo;
    }



}
